<template>
  <div class="app-container">
    <el-card style="border-radius: 10px">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单编号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入采购订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供货日期" prop="params">
        <el-date-picker
          clearable
          v-model="queryParams.params"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          placeholder="请选择供货日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="下单时间" prop="params1">
        <el-date-picker
          clearable
          v-model="queryParams.params1"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          placeholder="请选择下单时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="供应商" prop="vendorName">
        <el-input
          v-model="queryParams.vendorName"
          placeholder="请输入供应商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status"
                   placeholder="请选择状态"
                   clearable>
          <el-option label="已审批" value="0"/>
          <el-option label="待确定" value="3"/>
          <el-option label="待审批" value="4"/>
          <el-option label="已驳回" value="5"/>
          <el-option label="终止" value="6"/>
        </el-select>
      </el-form-item>
      <el-form-item label="采购员" prop="buyer">
        <el-input
          v-model="queryParams.buyer"
          placeholder="请输入采购员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采购部门" prop="buyerDept">
        <el-input
          v-model="queryParams.buyerDept"
          placeholder="请输入采购员部门名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划编号" prop="planNumber">
        <el-input
          v-model="queryParams.planNumber"
          placeholder="请输入采购计划编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编号" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入物料编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    </el-card>
    <div style="height: 15px"></div>
    <el-card style="border-radius: 10px">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['cg:cg:orderDetailTable:export:export']"
          >导出
          </el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
    <el-table border v-loading="loading" :data="tableList">
      <el-table-column label="采购订单编号" align="center" prop="orderCode"/>
      <el-table-column label="供货日期" align="center" prop="materialDeadline" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.materialDeadline, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="下单时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="供应商名称" align="center" prop="vendorName"/>
      <el-table-column label="联系人" align="center" prop="contact"/>
      <el-table-column label="联系人-电话" align="center" prop="contactTel"/>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag type="success" v-show="scope.row.status==0" dffect="dark">已审批</el-tag>
          <el-tag type="info" v-show="scope.row.status==3" dffect="dark">待确认</el-tag>
          <el-tag type="primary" v-show="scope.row.status==4" dffect="dark">待审批</el-tag>
          <el-tag type="danger" v-show="scope.row.status==5" dffect="dark">已驳回</el-tag>
          <el-tag type="danger" v-show="scope.row.status==6" dffect="dark">已终止</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="采购员" align="center" prop="buyer"/>
      <el-table-column label="采购部门" align="center" prop="buyerDept"/>
      <el-table-column label="采购计划编号" align="center" prop="planNumber"/>
      <el-table-column label="物料编号" align="center" prop="itemCode"/>
      <el-table-column label="物料名称" align="center" prop="itemName"/>
      <el-table-column label="规格型号" align="center" prop="specification"/>
      <el-table-column label="单位" align="center" prop="unitOfMeasure"/>
      <el-table-column label="物料分类名称" align="center" prop="itemTypeName"/>
      <el-table-column label="数量" align="center" prop="quantity"/>
      <el-table-column label="单价" align="center" prop="estimatedUnitPrice"/>
      <el-table-column label="总价" align="center" prop="total"/>
      <el-table-column label="名称" align="center" prop="clientName"/>
      <el-table-column label="备注" align="center" prop="remark"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    </el-card>
  </div>
</template>

<script>
import {listTable} from "@/api/mes/cg/orderDetailTable";

export default {
  name: "OrderDetailTable",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购订单明细表格数据
      tableList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderCode: null,
        materialDeadline: null,
        createTime: null,
        vendorName: null,
        status: null,
        buyer: null,
        buyerDept: null,
        planNumber: null,
        itemCode: null,
        itemName: null,
        clientName: null,
        params:[],
        params1:[],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询采购订单明细列表 */
    getList() {
      this.loading = true;
      const query = {...this.queryParams};
      if (query.params && query.params.length === 2) {
        query.params = {
          beginTime: query.params[0],
          endTime: query.params[1]
        };
      } else {
        query.params = null;
      }
      if (query.params1 && query.params1.length === 2) {
        query.params1 = {
          beginTime: query.params1[0],
          endTime: query.params1[1]
        };
      } else {
        query.params1 = null;
      }
      listTable(query).then(response => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      const query = {...this.queryParams};
      if (query.params && query.params.length === 2) {
        query.params = {
          beginTime: query.params[0],
          endTime: query.params[1]
        };
      } else {
        query.params = null;
      }
      if (query.params1 && query.params1.length === 2) {
        query.params1 = {
          beginTime: query.params1[0],
          endTime: query.params1[1]
        };
      } else {
        query.params1 = null;
      }
      this.download('cg/orderDetailTable/export', {
        ...query
      }, `采购订单明细_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
